#!/usr/bin/env python
#encoding=utf8
"""
@描述：测试一下职能标签能匹配到多少行业
@日期：2015年01月28日 星期三

@作者：hongxingfan
"""

import MySQLdb
import sys
reload(sys)
sys.setdefaultencoding("utf8")
from  DBUtils import MySQLDB

# 全局变量区域,大写
CONN = None


# 方法区域
def openConn(host,user,passwd,db,charset):
	try:
		global CONN
		CONN = MySQLdb.connect(host=host,user=user,passwd=passwd,db=db,charset=charset)
		#return conn
	except MySQLdb.Error, e:
		print("Error:  connect mysqldb is not complete...,%s,%s,%s" %(host,user,passwd))
		sys.exit(0)

# 类区域
class ThirdInfo:
	def __init__(self,name,id):
		self.name = name
		self.id = id

# 程序入口
if __name__ == "__main__":

	selectMap = """
			SELECT siteName,NAME,thirdName,otherSiteToKanZhun.thirdId FROM otherSiteToKanZhun
			LEFT JOIN jobclass_tag ON otherSiteToKanZhun.thirdId = jobclass_tag.thirdId
		"""
	# 连接配置
	host = "192.168.1.251"
	user = "root"
	passwd = ""
	db = "jobs"
	charset = "utf8"
	openConn(host,user,passwd,db,charset) # 获取连接

	# 封装成Map<string,Map<string,string>>结构
	keyValue = {}
	keyValue_1 = {}
	# 执行sql,装载到字典中
	key = None
	cur = CONN.cursor()
	cur.execute(selectMap)
	resultMap = cur.fetchall()
	for (siteName,name,thirdName,thirdId) in resultMap:
		if key != siteName and key != None:
			keyValue[key] = keyValue_1
			keyValue_1 = {}
		keyValue_1[name] = ThirdInfo(thirdName,thirdId)
		key = siteName
	# 测试输出
	for (k,v) in keyValue.items():
		for (kk,vv) in v.items():
			print("%s,%s,%s,%s" %(k,kk,vv.name,vv.id))
	# 遍历jobs数据表，找出与keyValue中相匹配的内容
